var assert 			= require("assert");
var exec 			= require('child_process').exec;

var resultAllJSON, resultAdjectivesVerbsAndNouns, globalManifest, testLanguageManifest;

describe('Preprocessing', function() {

	before(function(done) {
		exec('node ../execute -i ./data -o ./out',
		  function (error, stdout, stderr) {
		  	console.log(stdout)
		    if (error !== null) {
		      done(error);
		      return;
		    }
		    resultAllJSON = require("./out/last/languages/TestLanguage/all/data00000000.json");
		    resultAdjectivesVerbsAndNouns = require("./out/last/languages/TestLanguage/adjectives_verbs_nouns/data00000000.json");
		    globalManifest = require("./out/last/manifest.json");
		    testLanguageManifest = require("./out/last/languages/TestLanguage/manifest.json");
		    done();
		});
	});

	describe('Parses', function() {

		describe('Nouns', function() {
			it('basic', function(done) {
				assert.deepEqual(
					resultAllJSON["noun01"],
					{
					  "hits": 20,
					  "variants": {
					    "Noun": {
					      "english": [
					        "meaning noun01"
					      ]
					    }
					}
				});
				done();
			});

			it('compound', function(done) {
				assert.deepEqual(
					resultAllJSON["basic compond noun"],
					{
					  "hits": 0,
					  "variants": {
					    "Noun": {
					      "english": [
					        "meaning basic compond noun"
					      ]
					    }
					}
				});
				done();
			});
		});

		describe('Verbs', function() {
			it('Italian', function(done) {
				assert.deepEqual(
					resultAllJSON["infinitiveVerb"],
					{
					  "variants": {
					    "Verb": {
					      "tenses": {
					        "present": {
					          "cardinalities": {
					            "singular": {
					              "persons": {
					                "1st": "pres1pSin",
					                "2nd": "pres2pSin",
					                "3rd": "pres3pSin"
					              }
					            },
					            "plural": {
					              "persons": {
					                "1st": "pres1pPlu",
					                "2nd": "pres2pPlu",
					                "3rd": "pres3pPlu"
					              }
					            }
					          }
					        },
					        "past participle": "pp"
					      },
					      "english": [
					        "To meaning of infinitiveVerb"
					      ]
					    }
					  },
					  "hits": 0
					});
				done();
			});
		});

		describe('Verbs', function() {
			it('Spanish', function(done) {
				assert.deepEqual(
					resultAllJSON["spanishVerbInfinitive"],
					{
					  "variants": {
					    "Verb": {
					      "tenses": {
					        "preterite": {
					          "cardinalities": {
					            "plural": {
					              "persons": {
					                "3rd": "spanishVerb3pIndPret"
					              }
					            }
					          }
					        }
					      },
					      "english": [
					        "to stockpile",
					        "to hoard",
					        "to corner the market",
					        "to attack"
					      ]
					    }
					  },
					  "hits": 0
					});
				done();
			});
		});
	});

	describe('Excludes', function() {
		it('basic', function(done) {
			assert.deepEqual(
				resultAllJSON["aa"],
				{
				  "variants": {
				    "Noun": {
				      "english": [
				        "meaning a very short noun"
				      ]
				    }
				  },
				  "hits": 0
				}
			);
			assert(!resultAdjectivesVerbsAndNouns["aa"]);
			done();
		});
	});

	describe('Reports', function() {
		it('manifest', function(done) {
			assert.deepEqual(
				testLanguageManifest["stats"],
				{
				    "rawEntries": 14,
				    "finalEntries": 5,
				    "errors": {
				      "parsing": 0,
				      "processing": 0,
				      "missing": 82,
				      "orphaned": 1
				    }
				}
			);
			done();
		});
	});

	after(function() {
	});
});